// 配置axios
// import Vue from "vue";
import axios from "axios";
import qs from "qs";
let http = axios.create({
  // baseURL: baseURL,
  // baseURL: '/api',
  timeout: 1000 * 180
  // withCredentials: true
});
/**
 * 请求拦截
 */
http.interceptors.request.use(
  config => {
    // console.log(config)
    // 默认参数
    // var defaults = {};
    // 防止缓存，GET请求默认带_t参数
    if (config.method === "get") {
      config.params = {
        ...config.params
      };
    }
    if (
      /^application\/x-www-form-urlencoded/.test(config.headers["content-type"])
    ) {
      config.data = qs.stringify(config.data);
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
/**
 * 响应拦截
 */
http.interceptors.response.use(
  response => {
    return response;
  },
  err => {
    return Promise.reject(err);
  }
);
export default http;
